package com.cq.xjms.web.actions.sys;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.cq.xjms.model.Clazz;
import com.cq.xjms.model.Department;
import com.cq.xjms.model.Score;
import com.cq.xjms.model.Stat;
import com.cq.xjms.model.Student;
import com.cq.xjms.service.StatManager;
import com.cq.xjms.service.SysManager;
import com.cq.xjms.web.actions.BaseAction;

public class StatAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger log = Logger.getLogger(StatAction.class);
	private StatManager statManager;
	private SysManager sysManager;
	private Score score;
	private Clazz clazz;
	private Department department;
	private Student student;
	private List<Score> scores;
	private String scoreyear;
	private String scoreterm;
	private Stat stat;
	private Map<String,Object> params = new HashMap<String,Object>();
	private List<Stat> stats;
	public String scoreRank(){
	 try{
		 if(score ==null){
			 department=new Department();
			 clazz=new Clazz();
			 student=new Student();
			 score=new Score();
			 clazz.setDepartment(department);
			 student.setClazz(clazz);
			 score.setStudent(student);
		 }
		
		 stats=statManager.courseRank(score.getStudent().getClazz().getDepartment().getId(),score.getStudent().getClazz().getId(),null);
//		 totalRows=statManager.countCourseRank(score.getStudent().getClazz().getDepartment().getId(),score.getStudent().getClazz().getId());
	  }catch(Exception e){
		  log.error(""+e);
	  }
		return SUCCESS;
	}
	
	public String singleScoreRank(){
		if(score ==null){
			return INPUT;
		}
		try{
		scores=statManager.singleCourseRank(score.getCourse().getId(), getLimit());
		totalRows=statManager.singleCountCourseRank(score.getCourse().getId());
		}catch(Exception e){
			log.error(""+e);
		}
		
		return SUCCESS;
	}
	
	public String noPassRank(){
		
		String yearterm="";
		if(scoreyear !=null){
			yearterm +=scoreyear;
		}
		if(scoreterm !=null){
			yearterm +=scoreterm;
		}
		scores=statManager.noPassRank(yearterm, getLimit());
		totalRows=statManager.noPassCountRank(yearterm);
		return SUCCESS;
	}

	public SysManager getSysManager() {
		return sysManager;
	}

	public void setSysManager(SysManager sysManager) {
		this.sysManager = sysManager;
	}
	
	
	public Map<String, Object> getParams() {
		return params;
	}
	public void setParams(Map<String, Object> params) {
		this.params = params;
	}
	public StatManager getStatManager() {
		return statManager;
	}
	public void setStatManager(StatManager statManager) {
		this.statManager = statManager;
	}
	public Score getScore() {
		return score;
	}
	public void setScore(Score score) {
		this.score = score;
	}
	public List<Score> getScores() {
		return scores;
	}
	public void setScores(List<Score> scores) {
		this.scores = scores;
	}

	public Clazz getClazz() {
		return clazz;
	}

	public void setClazz(Clazz clazz) {
		this.clazz = clazz;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public String getScoreyear() {
		return scoreyear;
	}

	public void setScoreyear(String scoreyear) {
		this.scoreyear = scoreyear;
	}

	public String getScoreterm() {
		return scoreterm;
	}

	public void setScoreterm(String scoreterm) {
		this.scoreterm = scoreterm;
	}

	public List<Stat> getStats() {
		return stats;
	}

	public void setStats(List<Stat> stats) {
		this.stats = stats;
	}

	public Stat getStat() {
		return stat;
	}

	public void setStat(Stat stat) {
		this.stat = stat;
	}
	
	
}
